package com.tanhua.system.controller;

import com.tanhua.system.service.CommentsListService;
import com.tanhua.system.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("manage")
public class CommentsListController {

    @Autowired
    private CommentsListService commentsListService;

    /**
     * 查询评论列表
     */
    @GetMapping("messages/comments")
    public ResponseEntity<PageResult> queryCommentsList(
            @RequestParam Integer pageSize, // 页尺寸
            @RequestParam Integer page,     // 页数
            @RequestParam String sortProp,  // 排序字段
            @RequestParam String sortOrder, // ascending 升序 descending 降序
            @RequestParam Integer messageID // 消息id
    ) {
        try {
            PageResult pageResult = this.commentsListService.queryCommentsList(
                    pageSize, page, sortProp, sortOrder, messageID);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
